package com.zhangcong.controller;

import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.zhangcong.domain.LibBook;
import com.zhangcong.service.ILibBookService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图书信息Controller
 * 
 * @author zhangcong
 * @date 2023-05-24
 */
@Controller
@RequestMapping("/zhangc/book")
public class LibBookController extends BaseController
{
    private String prefix = "zhangc/book";

    @Autowired
    private ILibBookService libBookService;

    @RequiresPermissions("zhangc:book:view")
    @GetMapping()
    public String book()
    {
        return prefix + "/book";
    }

    /**
     * select count(1),left(s.signtime,4),
     * case when substring(s.signtime,6,1) =0 then substring(s.signtime,7,1) else substring(s.signtime,6,2) end 月,
     * substring(s.signtime,9,2)
     *  from edu_sign s
     * group by left(s.signtime,10)
     * @return
     */

    @RequestMapping("/main")
    @ResponseBody
    public String  main() {
        //Integer [][] arr1=new Integer[][]{ {2023,01,01,40},{2023,01,02,18},{2023,01,3,34},{2023,01,04,24}};
        //Integer [][] arr2=new Integer[][]{ {2023,01,01,60},{2023,01,02,40},{2023,01,03,85},{2023,01,04,50}};

        List<Map> list1 =libBookService.queryYDRS();//应出勤人
        List<Map> list2 =libBookService.querySJRS();//实际出勤人数

        System.out.println(list1);
        System.out.println(list2);

        JSONObject object = new JSONObject();
        object.put("data2",list1);
        object.put("data3",list2);
        return object.toJSONString();
    }

    /**
     * 查询图书信息列表
     */
    @RequiresPermissions("zhangc:book:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LibBook libBook)
    {
        startPage();
        List<LibBook> list = libBookService.selectLibBookList(libBook);
        return getDataTable(list);
    }

    /**
     * 导出图书信息列表
     */
    @RequiresPermissions("zhangc:book:export")
    @Log(title = "图书信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LibBook libBook)
    {
        List<LibBook> list = libBookService.selectLibBookList(libBook);
        ExcelUtil<LibBook> util = new ExcelUtil<LibBook>(LibBook.class);
        return util.exportExcel(list, "图书信息数据");
    }

    /**
     * 新增图书信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存图书信息
     */
    @RequiresPermissions("zhangc:book:add")
    @Log(title = "图书信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LibBook libBook)
    {
        return toAjax(libBookService.insertLibBook(libBook));
    }

    /**
     * 修改图书信息
     */
    @RequiresPermissions("zhangc:book:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        LibBook libBook = libBookService.selectLibBookById(id);
        mmap.put("libBook", libBook);
        return prefix + "/edit";
    }

    /**
     * 修改保存图书信息
     */
    @RequiresPermissions("zhangc:book:edit")
    @Log(title = "图书信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LibBook libBook)
    {
        return toAjax(libBookService.updateLibBook(libBook));
    }

    /**
     * 删除图书信息
     */
    @RequiresPermissions("zhangc:book:remove")
    @Log(title = "图书信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(libBookService.deleteLibBookByIds(ids));
    }
}
